<?php 

// Namespace

namespace Loop;


/**
 * CObjectHelper is a helper that provides various methods to manipulate objects
 *
 * @package		Loop
 * @category	Helper
 */

class CObjectHelper
{
	/**
	 * Check that all objects are similar
	 * 
	 * @param 	array 	$objects 			The array of objects
	 * @param 	string 	$objectClassName 	The object class name
	 * @param 	string 	$objectExtensionId	The object extension id
	 */

	public function checkObjectsSimilar($objects, &$objectClassName, &$objectExtensionId)
	{
		// Ensure all objects have the same classname/extension

		$previousClassName = null;
		$previousExtensionId = null;

		foreach ($objects as $object)
		{
			// Is it the first round? If so store classname/extension and continue

			if
			(
				($previousClassName == null) &&
				($previousExtensionId == null)
			)
			{
				$previousClassName = $object->className;
				$previousExtensionId = $object->extensionId;

				continue;
			}

			
			// Is the object from the same family as the previous one?

			if
			(
				($object->className != $previousClassName) ||
				($object->extensionId != $previousExtensionId)
			)
			{
				e
				(
					EXCEPTION_OBJECT_AGGREGATE_OBJECTS_NOT_SIMILAR,
					array
					(
						'objects' => print_r($objects, true)
					)
				);
			}
			
			
			// Store the classname/extension for the next round

			$previousClassName = $object->className;
			$previousExtensionId = $object->extensionId;
		}


		// Return the final classname/extension

		$objectClassName = $previousClassName;
		$objectExtensionId = $previousExtensionId;
	}
}

?>
